//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-10-29  Jed Young  Creation
//

using gfx
using fwt
using chunmapModel
using chunmapData
using chunmapUtil
using chunmapView


**
** show the Distance
**
@Js
class DistanceTool : LineTool
{
  override protected Void mouseMove(Event e)
  {
    if (!draging) return

    map.paintOnBuffer |g|
    {
      map.drawOriginImage(g, 0, 0)
      g.pen = Pen { width = 3 }
      g.drawPolyline2(toIntArray(e.pos.x, e.pos.y))
      dis := getLength(e.pos.x, e.pos.y)
      g.drawText(dis.toLocale("#,###")+"m", e.pos.x+5, e.pos.y-20)
    }
    e.consume
    map.repaint
  }

  private Float getLength(Int x, Int y)
  {
    p := map.view.screen2World.call(Coord(x.toFloat, y.toFloat))
    dup := lse.dup
    dup.add(p)
    return LinearReference.getWorldLength(dup.toCoordSeq)
  }
}